﻿// <copyright file="NtObjectList.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// This class represents an NT Object Exclusion list.
    /// </summary>
    /// <remarks>
    /// This class corresponds to section 0x07 of a CP file.
    /// </remarks>
    internal class NtObjectList
    {
        /// <summary>
        /// The list of object names that will get special handling.
        /// </summary>
        private List<NtObjectListEntry> objectList;

        /// <summary>
        /// Initializes a new instance of the NtObjectList class.
        /// </summary>
        /// <param name="dataStream">
        /// A memory stream that contains the raw data for this section of the CP file.
        /// </param>
        public NtObjectList(System.IO.MemoryStream dataStream)
        {
            this.objectList = new List<NtObjectListEntry>();
            this.ReadSection(dataStream);
        }

        /// <summary>
        /// Gets the list of objects that will get special handling on the client.
        /// </summary>
        public List<NtObjectListEntry> ObjectList
        {
            get { return this.objectList; }
        }

        /// <summary>
        /// Reads the actual data for this section from the memory stream.
        /// </summary>
        /// <param name="dataStream">
        /// A memory stream containing the raw data for the section.
        /// </param>
        private void ReadSection(System.IO.MemoryStream dataStream)
        {
            System.IO.BinaryReader streamReader = new System.IO.BinaryReader(dataStream);

            NtObjectListEntry entry;
            do
            {
                entry = new NtObjectListEntry(dataStream);
                this.objectList.Add(entry);
            }
            while (entry.EntrySize > 0);

            streamReader.Close();
        }
    }
}
